<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
        <el-form-item label="名称" prop="name">
          <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['secure:checkAndAcceptList:add']">新增</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
            v-hasPermi="['goods:consumeIn:export']">导出</el-button>
        </el-col> -->
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="printBox"
            v-hasPermi="['secure:checkAndAcceptList:print']">打印</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table @selection-change="handleSelectionChange" fit v-loading="loading" border :data="dataList">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column show-overflow-tooltip label="状态" width="100">
        <template slot-scope="scope">
          <el-tag size="mini">{{ scope.row.statusName }}</el-tag>
        </template>
      </el-table-column>
        <el-table-column min-width="150" label="名称" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-link @click="handleDetail(scope.row)" type="primary">{{
              scope.row.name
            }}</el-link>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="入库序号" min-width="150" prop="code" />
        <el-table-column show-overflow-tooltip min-width="150" label="入库日期" prop="joinDate" />
        <el-table-column show-overflow-tooltip label="入库数量" min-width="150" prop="num" />
        <el-table-column show-overflow-tooltip min-width="150" label="验收情况" prop="conditionValue" />
        <el-table-column show-overflow-tooltip min-width="150" label="有效期" prop="validDate" />
        <el-table-column show-overflow-tooltip min-width="150" label="验收人" prop="checkUserName" />
        <el-table-column show-overflow-tooltip min-width="150" label="确认日期" prop="confirmDate" />
        <el-table-column show-overflow-tooltip label="是否可用于日常实验" min-width="150" prop="isTest" >
            <template slot-scope="scope">
               <div class="df"> {{ scope.row.isTest==1?'是':'否' }}</div>
            </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="240" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['secure:checkAndAcceptList:info']"
              @click="handleDetail(scope.row)">详情</el-button>
            <!-- v-if="scope.row.status==='end'&&scope.row.isCanChecked==1" -->
            <el-button size="mini" type="text" icon="el-icon-view" v-if="scope.row.statusName == '草稿'" v-hasPermi="['secure:checkAndAcceptList:check']"
              @click="handleCheck(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
  
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
      <!-- 打印模板位置 -->
      <PrintBox :checkNum="8" :printRow="printList" :checkLabel="'contentList'" :isVertical="false" id="printBox" :isPageSize="false">
      <template slot="title" slot-scope="scope">
        <div>化学试剂药品验收记录表 STET/B/07-3</div>
      </template>
      <template slot-scope="scope">
        <div>
          <div style="display: flex;align-items: center;justify-content: space-between;margin-top: 20px;">
            <div>检测单位名称：苏州交通工程试验检测中心有限公司</div>
            <div style="padding-right: 150px;">记录编号：</div>
          </div>
        </div>
        <table style="border-collapse: collapse; table-layout: fixed" border="1" cellspacing="0" class="table-page">
          <tr style="height: 5mm">
            <td style="width: 20mm">入库序号</td>
            <td style="width: 20mm">名称</td>
            <td style="width: 25mm">入库日期</td>
            <td style="width: 20mm">入库量</td>
            <td style="width: 45mm">验收情况</td>
            <td style="width: 35mm">有效期</td>
            <td style="width: 20mm">验收人</td>
            <td style="width: 35mm">确认日期</td>
            <td style="width: 30mm">是否可用于日常试验</td>
            <td style="width: 25mm">技术负责人</td>

          </tr>
          <tr v-for="(e, i) in 15">
            <td>{{ printList[i] && printList[i].code }}</td>
            <td>{{ printList[i] && printList[i].name }}</td>
            <td>{{ printList[i] && printList[i].joinDate }}</td>
            <td>{{ printList[i] && printList[i].num }}</td>
            <td>
              <el-checkbox v-model="printList[i] && printList[i].conditionValue == '未开封，未受潮，包装完好。'" label="未开封，未受潮，包装完好"></el-checkbox>
                <el-checkbox v-model="printList[i] && printList[i].conditionValue == '其它'" label="其它"></el-checkbox>
            </td>
            <td>{{ printList[i] && printList[i].validDate }}</td>
            <td>{{ printList[i] && printList[i].checkUserName }}</td>
            <td>{{ printList[i] && printList[i].confirmDate }}</td>
            <td>
                <el-checkbox v-model="printList[i] && printList[i].isTest == 1" label="是"></el-checkbox>
                <el-checkbox v-model="printList[i] && printList[i].isTest == 0" label="否"></el-checkbox>
              <!-- {{ printList[i] && printList[i].isTest == 0 ? }} -->
            </td>
            <td>  <img  v-if="printList[i] && CheckApprove(scope, 'jsfzr').ShowImg"
                      style="width: 80px;"
                      :src="CheckApprove(scope, 'jsfzr').ApproveImg"
                    /></td>
          </tr>
        </table>
        <div class="page-bottom" style="page-break-after: always">
          <div class="desc">注：本表格自2023年1月1日起生效</div>
        </div>
      </template>
    </PrintBox>
    </div>
  </template>
  
  <script>
  import {
    consume_join_check_list,
    delconsume_Join,
    effectgoodsDirectory,
  } from "@/api/quality/goods/consumeIn.js";
  import printStyle from "@/utils/print.js";
  export default {
    name: "consumeIn",
    data() {
      return {
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        dataList: [],
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: undefined,
          chemicals: 1,
        },
        // 日期范围
        dateRange: [],
        infos: [], //勾选的数据
        userList: [],
        deptOptions: [],
        printList: [],
  
      };
    },
    created() {
      this.getList();
      // this.getDeptTree();
    },
    methods: {
      handleStatusChange(row) {
        let text = row.effectStatus === "1" ? "启用" : "禁用";
        this.$modal
          .confirm('确认要"' + text + '""' + row.name + '"目录吗？')
          .then(function () {
            return effectgoodsDirectory(row.consumeGoodsJoinId, row.effectStatus);
          })
          .then(() => {
            this.$modal.msgSuccess(text + "成功");
          })
          .catch(function () {
            row.effectStatus = row.effectStatus === "0" ? "1" : "0";
          });
      },
      printBox() {
        //infos  勾选的数据 如果有勾选就打印勾选。
        if (this.infos.length) {
          this.printList = this.infos;
        } else {
          //反之打印当前整个列表
          this.printList = this.dataList;
        }
        console.log(process.env.VUE_APP_TITLE);
        setTimeout(() => {
          document.title = "化学试剂药品验收记录表 STET/B/07-3";
  
          this.$print({
            printable: "printBox", //打印区域id
            type: "html", //打印类型是html
            scanStyles: false,
            targetStyles: ["*"],
            style: this.workStyle(),
            onPrintDialogClose: () => {
              document.title = process.env.VUE_APP_TITLE;
            },
          });
        }, 500);
      },
      // 可以自定义样式  printStyle 是公共样式 切勿私自修改
      workStyle() {
        return `${printStyle}
          table,
          table tr th,
          table tr td {
            height:17mm;
            padding: 0px;
            font-size: 12px;
          }
          .desc{
          text-align: left; font-size: 12px; margin-top: 10px
        }
              .df {
                  display: flex;
                }
        `;
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.consumeGoodsJoinId);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
        this.infos = selection;
      },
  
      /** 修改按钮操作 */
      handleUpdate(row) {
        const configId = row.consumeGoodsJoinId || this.ids;
        this.$router.push("./addConsumeIn?isEdit=true&id=" + configId);
      },
      handleDetail(row) {
        this.$router.push(
          "./checkandaccept?isInfo=true&id=" + row.consumeGoodsJoinCheckId
        );
      },
      handleCheck(row) {
        this.$router.push(
          "./checkandaccept?isEdit=true&id=" + row.consumeGoodsJoinCheckId
        );
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const configId = row.consumeGoodsJoinId || this.ids;
  
        this.$modal
          .confirm('是否确认删除ID为"' + configId + '"的数据项？')
          .then(function () {
            return delconsume_Join(configId);
          })
          .then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => { });
      },
      handleAdd() {
        this.$router.push("./addConsumeIn");
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        consume_join_check_list({
          ...this.addDateRangeTime(
            this.queryParams,
            this.dateRange,
            "startEndDate",
            "endEndDate"
          ),
        }).then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
  
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      handleExport() {
        this.download(
          "system/consume_Join/export",
          {
            ...this.queryParams,
          },
          `消耗品入库表_${this.parseTime(
            new Date().getTime(),
            "{y}-{m}-{d}"
          )}.xlsx`
        );
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
    },
  };
  </script>
  <style lang="scss" scoped>
  ::v-deep .el-dialog__body {
    img {
      width: 100%;
    }
  }
  .df{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  </style>
  